﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CreatDepartment.aspx.cs"
    Inherits="ZX.WebApp.EditWidows.OrganizationalManager.CreatDepartment" %>

<script src="http://localhost:30903/Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/container/assets/skins/sam/container.css" />
    <link href="../../Styles/default/calendar.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/element/element-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/datasource/datasource-min.js"></script>
    <!-- OPTIONAL: Connection Manager (enables XHR for DataSource) -->
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
    <!-- OPTIONAL: Get Utility (enables dynamic script nodes for DataSource) -->
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/get/get-min.js"></script>
    <!-- OPTIONAL: Drag Drop (enables resizeable or reorderable columns) -->
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/dragdrop/dragdrop-min.js"></script>
    <!-- OPTIONAL: Calendar (enables calendar editors) -->
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/calendar/calendar-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/resize/resize-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/paginator/paginator-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/event-delegate/event-delegate-min.js"></script>
    <script src="../../Scripts/jquery-1.6.min.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.json-2.2.min.js" type="text/javascript"></script>
    <script src="../../Scripts/Jquery.form.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.calendar.js" type="text/javascript"></script>
    <script src="../../Scripts/Appjs/jquery.CheckData.js" type="text/javascript"></script>
    <script src="../../Scripts/common.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="divCompany" style="display: none">
        <fieldset>
            <legend><font color='blue'>公司基本信息</font> </legend>
            <table id="CompanyTable" cellpadding="0" cellspacing="0" class="cmxform" border="0.5px"
                style="width: 100%; line-height: 25px">
                <tr>
                    <td>
                        公司名称：
                    </td>
                    <td>
                        <input type="text" name="DeptName" id="DeptName" requiretype="1" /><font color="red">*</font>
                    </td>
                    <td>
                        虚拟部门:
                    </td>
                    <td>
                        <asp:DropDownList ID="drpCompany" runat="server" Height="16px" Width="39px">
                            <asp:ListItem Value="0">否</asp:ListItem>
                            <asp:ListItem Value="1">是</asp:ListItem>
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr>
                    <td>
                        联系电话：
                    </td>
                    <td>
                        <input type="text" name="Phone" id="Phone" />
                    </td>
                    <td>
                        传真：
                    </td>
                    <td>
                        <input type="text" name="Fax" id="Fax" />
                    </td>
                </tr>
                <tr>
                    <td>
                        创建日期：
                    </td>
                    <td>
                        <input runat="server" type="text" readonly="readonly" class="yui-date" dtype="D"
                            id="SendTIme" name="AddTime" /><font color="red">*</font>
                    </td>
                    <td>
                        失效日期：
                    </td>
                    <td>
                        <input runat="server" type="text" readonly="readonly" class="yui-date" dtype="D"
                            id="DtCompanyExpireDate" name="ExpireDate" />
                    </td>
                </tr>
                <tr>
                    <td>
                        组织架构码：
                    </td>
                    <td>
                        <input type="text" name="DeptPath" value='<%=DeptPath %>' readonly="readonly" />
                    </td>
                    <td>
                        邮政编码：
                    </td>
                    <td>
                        <input type="text" name="PostCode" />
                    </td>
                </tr>
                <tr>
                    <td>
                        公司地址：
                    </td>
                    <td>
                        <input type="text" name="Address" />
                    </td>
                    <td>
                        公司主页:
                    </td>
                    <td>
                        <input type="text" name="URL" />
                    </td>
                </tr>
                <tr>
                    <td>
                        Email：
                    </td>
                    <td>
                        <input type="text" name="Email" />
                    </td>
                    <td>
                        法人代表：
                    </td>
                    <td>
                        <input type="text" name="ArtificialPerson" />
                    </td>
                </tr>
            </table>
        </fieldset>
        <br />
        <br />
        <fieldset id="companyPostionFieldset">
            <legend><font color='blue'>公司负责人职位</font> </legend>
            <table id="Companyheaderposttable" cellpadding="0" cellspacing="0" border="0.5px"
                style="width: 60%; padding-top: 0px; line-height: 25px">
                <tr>
                    <td>
                        职务类型：
                    </td>
                    <td>
                        <select id="postType" onchange="getDutyTypeId();" style="width: 126px">
                    </td>
                </tr>
                <tr>
                    <td>
                        职务：
                    </td>
                    <td>
                        <select id="SelpostInfo" name="PTypeID" style="width: 126px">
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>
                        负责人职位：
                    </td>
                    <td>
                        <input type="text" style="width: 126px" name='PositionName' id="CompanyPositionName" />
                    </td>
                </tr>
            </table>
        </fieldset>
    </div>
    <div id="divDepartment">
        <fieldset>
            <legend><font color='blue'>部门基本信息</font> </legend>
            <table id="deptTable" cellpadding="0" cellspacing="0" border="0.5px" style="width: 100%;
                line-height: 25px">
                <tr>
                    <td>
                        部门名称：
                    </td>
                    <td>
                        <input type="text" name="DeptName" id="Text1" requiretype="1" /><font color="red">*</font>
                    </td>
                    <td>
                        联系电话：
                    </td>
                    <td>
                        <input type="text" name="Phone" />
                    </td>
                </tr>
                <tr>
                    <td>
                        组织架构码：
                    </td>
                    <td>
                      <input type="text" name="DeptPath" value='<%=DeptPath %>' readonly="readonly" />
                    </td>
                    <td>
                        虚拟部门：
                    </td>
                    <td>
                        <asp:DropDownList ID="drpDepartment" runat="server" Height="16px" Width="39px">
                            <asp:ListItem Value="0">否</asp:ListItem>
                            <asp:ListItem Value="1">是</asp:ListItem>
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr>
                    <td>
                        创建日期：
                    </td>
                    <td>
                        <input runat="server" type="text" readonly="readonly" class="yui-date" dtype="D"
                            id="DeptCreateTime" name="AddTime" /><font color="red">*</font>
                    </td>
                    <td>
                        失效日期：
                    </td>
                    <td>
                        <input runat="server" type="text" readonly="readonly" class="yui-date" dtype="D"
                            id="ExpireDate" name="ExpireDate" />
                    </td>
                </tr>
                <tr>
                    <td>
                        辅助码：</td>
                    <td>
                        <input runat="server" type="text" readonly="readonly" class="yui-date" dtype="D"
                            id="HelpCode" name="HelpCode" /></td>
                    <td>
                        &nbsp;</td>
                    <td>
                        &nbsp;</td>
                </tr>
                <tr>
                    <td>
                        部门职责：
                    </td>
                    <td colspan="3">
                        <textarea name="DeptFunction" cols="40" rows="2"></textarea>
                    </td>
                </tr>
                <tr>
                    <td>
                        备注:
                    </td>
                    <td colspan="3">
                        <textarea name="Description" cols="40" rows="2"></textarea>
                    </td>
                </tr>
            </table>
        </fieldset>
        <br />
        <br />
        <fieldset id="deptPostionFieldset" style="display:none">
            <legend><font color='blue'>部门负责人职位</font> </legend>
            <table id="Deptheaderposttable" cellpadding="0" cellspacing="0" border="0.5px" style="width: 80%;
                line-height: 25px">
                <tr>
                    <td>
                        职务类型：
                    </td>
                    <td>
                        <select id="Select1" onchange="getDutyTypeId();" style="width: 126px">
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>
                        职务：
                    </td>
                    <td>
                        <select id="SelpostInfo1" name="PTypeID" style="width: 126px">
                    </td>
                </tr>
                <tr>
                    <td>
                        负责人职位：
                    </td>
                    <td>
                        <input type="text" id="deptPositionName" name="PositionName">
                    </td>
                </tr>
            </table>
        </fieldset>
    </div>
    </form>
</body>
<script type="text/javascript">
        //设置控件为数字控件
      var deptType=getarg(0);
       //加载职务类型
        var handleSuccess=function(o){
            $("#postType").comBind("["+o.responseText+"]","PhraseID","PhraseText");
            $("#Select1").comBind("["+o.responseText+"]","PhraseID","PhraseText");
            getDutyTypeId();
             
        }
        
        var handleFailure = function (o) {
            alert(o.responseText);
        }
         var callback=
        {
            success: handleSuccess,
            failure: handleFailure,
            argument: { foo: "foo", bar: "bar" }
        };
       var url = "DataProcessin.aspx?entity=DutyType&action=get&r="+Math.random()+"";
           var request = YAHOO.util.Connect.asyncRequest('Post', url, callback);
        
       //加载职务类型
        var handleSuccess1=function(o){
           if(deptType==1)
           {
                $("#SelpostInfo").empty();
                $("#SelpostInfo").comBind("["+o.responseText+"]","ID","Name");
           }
           else
           {
                $("#SelpostInfo1").empty();
                $("#SelpostInfo1").comBind("["+o.responseText+"]","ID","Name");
           }     
        }
        
        var handleFailure1 = function (o) {
            if(deptType==1)
           {
                $("#SelpostInfo").empty();
           }
           else
           {
                $("#SelpostInfo1").empty();
           }     
        }
         var callback1=
        {
            success: handleSuccess1,
            failure: handleFailure1,
            argument: { foo: "foo", bar: "bar" }
        };
       var getDutyTypeId=function(){
         var depttypeId="";
         if(deptType==1)
         {
              depttypeId=$("#postType").val();
          }
          else
          {
             depttypeId=$("#Select1").val();
           }
         var url = "DataProcessin.aspx?entity=DutyInfo&action=get&r="+Math.random()+"&dutyTypeId="+depttypeId+"";
         var request = YAHOO.util.Connect.asyncRequest('Post', url, callback1);

       }
      //控制显示部门编辑与公司编缉
       if(deptType==1)
       {
         $("#divCompany").show();
         $("#divDepartment").hide();
         
       }
       else
       {
          $("#divCompany").hide();
          $("#divDepartment").show();
       }
      

        //数据保存
        
//        var Parent = parent;
        <asp:Literal ID="EditTemplate" runat="server"></asp:Literal>
        <asp:Literal ID="EditTemplate1" runat="server"></asp:Literal>
     
      //设置编辑状态下不显示负责人职位设置栏位
      if(<%=IsEdit%>=="1")
      {
        $("#companyPostionFieldset").hide();
        $("#deptPostionFieldset").hide();
        $("#CompanyTable").JSONToForm($.toJSON(instancedept[0]));
        $("#deptTable").JSONToForm($.toJSON(instancedept[0]));

      }
        
        function setValue()
        {
           //var o = $("#deptTable").extractObject();
        
           if(deptType==1)
           {
               //添加公司
               //1:公司负责人职位
                if(<%=IsEdit%>!="1")
               {
                   var PostID='<%=getGuid %>';
                   var deptID='<%=getGuid %>';
                   if($("#CompanyPositionName").val()!="")
                   {
                       $("#Companyheaderposttable").SetFormValueToObject(instancePost[0]);
                        instancePost[0].PostID=PostID;//职位ID
                        instancePost[0].DeptID=deptID;
                        instancePost[0].PositionID=$("#SelpostInfo").val();
                   }
                   $("#CompanyTable").SetFormValueToObject(instancedept[0]);
                   //编辑公司
                   instancedept[0].DeptID=deptID;
                   instancedept[0].DeptPath='<%=DeptPath %>';
                   instancedept[0].ParentID=parent.fkey;
                   instancedept[0].Manager=PostID;//负责人职位ID\
               }
               instancedept[0].DeptType="1";
               instancedept[0].IsVirtualDepartment=$("#drpCompany").val();
           }
           else
           {
               if(<%=IsEdit%>!="1")
                {
                    var PostID='<%=getGuid %>';
                    var deptID='<%=getGuid %>';
                    //添加部门 
                    //1:添加部门负责人
                    if($("#deptPositionName").val()!="")
                    {
                        $("#Deptheaderposttable").SetFormValueToObject(instancePost[0]);
                        instancePost[0].PostID=PostID;
                        instancePost[0].DeptID=deptID;
                        instancePost[0].PositionID=$("#SelpostInfo1").val();
                    }
                    else{
                        $("#deptTable").SetFormValueToObject(instancedept[0]);
                        instancedept[0].ParentID=parent.fkey;
                        instancedept[0].DeptID=deptID;
                        instancedept[0].DeptPath='<%=DeptPath %>';
                        instancedept[0].Manager=PostID;//负责人职位ID\
                        instancedept[0].DeptType="2";
                    }
                 }
                 else
                 {
                        $("#deptTable").SetFormValueToObject(instancedept[0]);
                        //instancedept[0].ParentID=parent.fkey;
                        //instancedept[0].DeptID=deptID;
                        //instancedept[0].DeptPath='<%=DeptPath %>';
                        //instancedept[0].Manager=PostID;//负责人职位ID\
                        //instancedept[0].DeptType="2";   
                 }
                 instancedept[0].IsVirtualDepartment=$("#drpDepartment").val();
            }
           returnValue(instancedept[0].DeptID,instancedept[0].DeptName,instancedept[0].DeptType);
        }


        //数据保存
        function Save()
        {  
             var url = "../../Extend/AjaxData/DataSave.aspx";
              setValue();
              var json =$.toJSON(instancedept[0]).replace(/'/g,"[B]");
              if(<%=IsEdit%>!="1")
              {
                  var postionjson =$.toJSON(instancePost[0]).replace(/'/g,"[B]");
              }
              if(deptType==1)
                {
                     //执行客户端验证
                    if($("#CompanyTable").checkInputData()==1&&$("#SelpostInfo").val()!=null)
                    {
                         if(<%=IsEdit%>!="1")
                            {
                             if($("#CompanyPositionName").val()!="")
                               {
                                   $("#Companyheaderposttable").SaveData(url,"DatPost",postionjson,"insert");
                                }
                                $("#CompanyTable").SaveData(url,"DatDepartment",json,"insert");
                            }
                            else
                            {
                                $("#CompanyTable").SaveData(url,"DatDepartment",json,"update");
                            }
                           
                         return true;
                     }
                     else
                     {
                        alert("你填写的资料未通过格式验证");
                          return false;
                     }
                  }
                 else
                 {
                     //debugger
                     //if($("#deptTable").checkInputData()==1&&$("#SelpostInfo1").val()!=null)
                    {
                            if(<%=IsEdit%>!="1")
                            {
                               if($("#deptPositionName").val()!="")
                                 {
                                     $("#Deptheaderposttable").SaveData(url+"action=insert","DatPost",postionjson);
                                 }
                                 $("#deptTable").SaveData(url,"DatDepartment",json,"insert");
                             }
                             else
                             {
                                  $("#deptTable").SaveData(url,"DatDepartment",json,"update");
                             }
                            return true;
                     }
//                     else
//                     {
//                        alert("你填写的资料未通过格式验证");
//                        return false;
//                     }
                 }
     }
    
     var returnValue=function(newdeptId,deptName,newdeptType)
     {
       parent.newDeptID=newdeptId;
       parent.deptName=deptName;
       parent.newdeptType=newdeptType;
     }
        
//        $(document).ready(function(){
//           // handleSuccess();
//        });
   $(document).ready(function () {
    $('#SendTIme').cld();
    $('#DeptCreateTime').cld();
    $("#DtCompanyExpireDate").cld();
    $('#ExpireDate').cld();
});
      
</script>
</html>
